package com.explorer.ider.bootguide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.explorer.ider.bootguide.R;
import com.explorer.ider.bootguide.itembean.ApkInfo;
import java.util.List;


/**
 * Created by Administrator on 2018/5/31.
 */

public class AppSelectAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<ApkInfo> apkInfos;


    public AppSelectAdapter(Context context,List<ApkInfo>apkInfos){
        this.apkInfos=apkInfos;
        this.context=context;
        this.layoutInflater=LayoutInflater.from(context);

    }


    @Override
    public int getCount() {
        return apkInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return apkInfos.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }



    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        Holder holder=null;
        if (view==null){
            view=layoutInflater.inflate(R.layout.app_select_item_layout,null);
            holder=new Holder();
            holder.apkIcon=(ImageView)view.findViewById(R.id.app_select_iv);
            holder.apkName=(TextView)view.findViewById(R.id.app_select_tv);
            view.setTag(holder);

        }else {
            holder=(Holder) view.getTag();
        }

        ApkInfo apkInfo=apkInfos.get(i);
        holder.apkName.setText(apkInfo.getApkName());
        holder.apkIcon.setImageDrawable(apkInfo.getApkIcon());


        return view;
    }

    class Holder {
        TextView apkName;
        ImageView apkIcon;


    }


}
